package com.warehouse.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.warehouse.dto.PageResult;
import com.warehouse.dto.ResultCode;
import com.warehouse.entity.ProType;
import com.warehouse.entity.ProTypeExample;
import com.warehouse.mapper.ProTypeMapper;
import com.warehouse.service.ProTypeService;
import com.warehouse.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @program: warehouse
 * @description:
 * @author: xiaojiu
 * @create: 2021-01-13 21:08
 */
@Service
public class ProTypeServieImpl implements ProTypeService {
    @Autowired(required = false)
    private ProTypeMapper proTypeMapper;
    //   @Autowired(required = false)
//   private ProTypeExample example ;
    @Autowired(required = false)
    private IdWorker idWorker;

    @Override
    public PageResult<ProType> findAllProType(Integer currentPage, Integer pageSize, String sortName) {
//        ProTypeExample example = new ProTypeExample();
//        example.setOffset((currentPage - 1) * pageSize); //limit 的第一个参数
//        System.out.println(example.getOffset());
//        example.setLimit(pageSize); //limit 的 第二个参数
//        example.setOrderByClause(sortName); // order by 的参数
        PageHelper.startPage(currentPage, pageSize, "create_time desc");
        List<ProType> proTypeList = proTypeMapper.findProTyoeInfo();
        PageInfo<ProType> proTypePageInfo = new PageInfo<>(proTypeList);
        return new PageResult<>(proTypePageInfo.getTotal(), proTypePageInfo.getList(), (long) proTypePageInfo.getPages());
    }

    @Override
    public ProType insertProType(ProType proType) {
        String id = idWorker.nextId() + "";
        proType.setId(id);
        proType.setCreateTime(new Date());
        int i = proTypeMapper.insertSelective(proType);
        return proType;
    }

    @Override
    public boolean delProTypeByid(String id) {
        int i = proTypeMapper.deleteByPrimaryKey(id);
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean updateProType(ProType proType) {
        int i = proTypeMapper.updateByPrimaryKeySelective(proType);
        if (i > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<ProType> findProTyoeInfo() {
        List<ProType> list = proTypeMapper.findProTyoeInfo();
        return list;
    }

    @Override
    public List<ProType> findProType(ProType proType) {
        List<ProType> list = proTypeMapper.findProType(proType);
        return list;
    }


}
